//
//  BusinessMemberfindIntegralListViewController.m
//  HAODE
//
//  Created by panquanReabam.com on 15/9/26.
//  Copyright (c) 2015年 reabam.com. All rights reserved.
//

#import "BusinessMemberfindIntegralListViewController.h"
#import "OrderDetailViewController.h"
#import "UIImage+RTTint.h"
#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "InstallConfirmViewController.h"
#import "huiyuandengjiViewController.h"
#import "UIImageView+WebCache.h"
#import "shouyingViewController.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "indIntegralListCell.h"

@interface BusinessMemberfindIntegralListViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UISearchBarDelegate>
@property (strong, nonatomic) NSString *areaValue;
@property (strong, nonatomic) NSString*cityValue;
@property (retain, nonatomic)NSString*sats;
@property (retain, nonatomic)NSString*orderSort;
@end

@implementation BusinessMemberfindIntegralListViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    
    NSMutableArray* createDate;
    NSMutableArray* integral;
    NSMutableArray* memo;
    NSMutableArray*companyName;
    BOOL saveAccount;
    BOOL saveAccount1;
    NSString *result;
    int pageNumber;
    MBProgressHUD *progressHud;
    UIView* backview1;
    UIScrollView*myscrollView;
    NSString* sous;
 
    NSString*meiyousuos;
    UIView*view3;
    NSString*TotalCount;
    
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];

    
    
    
}
- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBarHidden=NO;
        self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    
    self.title=@"积分明细";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];
    
    
    [self add];
    
}



- (void)viewDidLoad
{
    
    [super viewDidLoad];

   
    
    
    
    _table.delegate=self;
    _table.dataSource=self;
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
   
    
    
    
}
-(void)add{
    
    
    
    
    
    pageNumber = 1;
   
    
    
    
    
    
    
    commdity=[HAODEsingleton shared];
    
    meiyousuos=@"meiyou";
    sous=nil;
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"1" forKey:@"pageIndex"];
    [param setValue:@"20" forKey:@"pageSize"];
    [param setValue:commdity.memberId forKey:@"memberId"];
  
    
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"Business/Member/findIntegralList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                TotalCount=[severDataDict.dataDict objectForKey:@"totalIntegral"];
                UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,90/2)];
                view.backgroundColor= zuiqianhuicolor;
                 _table.tableHeaderView=view;
                
                
                UILabel*jifen=[[UILabel alloc]initWithFrame:CGRectMake(17, 0, ScreenWidth, 45)];
                jifen.text=@"当前积分";
                jifen.font=[UIFont systemFontOfSize:15];
                [view addSubview:jifen];
                
//                UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 45-0.35, ScreenWidth, 0.35)];
//                lineLabel1.backgroundColor=[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
//                [view addSubview:lineLabel1];
                

                UILabel*jifens=[[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth-200, 0, 185, 45)];
                jifens.text=[NSString stringWithFormat:@"%@",TotalCount];
                jifens.textAlignment=NSTextAlignmentRight;
                jifens.textColor=hongsecolor;
                jifens.font=[UIFont boldSystemFontOfSize:18];
                [view addSubview:jifens];
                
                createDate= [[NSMutableArray alloc] init];
                integral= [[NSMutableArray alloc] init];
                memo= [[NSMutableArray alloc] init];
                companyName= [[NSMutableArray alloc] init];
                for (NSDictionary* dicc in arrr )
                {
                    [memo addObject:[dicc valueForKey:@"memo"]];
                    [integral addObject:[dicc valueForKey:@"integral"]];
                    [createDate addObject:[dicc valueForKey:@"createDate"]];
                    
                }
                [_table reloadData];
                
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [integral count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    indIntegralListCell* cell = (indIntegralListCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"indIntegralListCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
   
    cell.title.text=[memo objectAtIndex:indexPath.row];
    NSRange range={0,10};
    
    NSString* string =[[createDate objectAtIndex:indexPath.row] substringWithRange:range];
    
    
//  newsDate = @"2013-08-09 17:01";
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy.MM.dd"];
    

    NSDate *newsDateFormatted = [dateFormatter dateFromString:string];
    NSString *str= [dateFormatter stringFromDate:newsDateFormatted];
    
    UIImage *img=[UIImage imageNamed:@"jifenyuanquan.png"];
    
    UIImage *tinted = [img rt_tintedImageWithColor:luseColor ];
    cell.iamge.image=tinted;
    cell.time.text=str;
    cell.price.text=[NSString stringWithFormat:@"%@",  [integral objectAtIndex:indexPath.row]];

//    if (indexPath.row==8) {
//         cell.price.text=@"9";
//    }
//    if (indexPath.row==4) {
//        cell.price.text=@"988387";
//    }
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 90;
}

#pragma mark - Table view delegate

- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

@end

